﻿@inject IHttpService _httpService
@inject IDataCacheService _dataCacheService
@inject NavigationManager NavigationManager
@inject IPageModelCatche<List<FriendLinkItemModel >> _pageModelCatche
<CnGalWebSite.Components.Containers.MiniModeContainer>
    <section class="friend-links-card">
        <h2>友情链接</h2>

        <div class="group">
            @foreach (var item in _items)
            {
                <MDCard Class="item" Href="@item.Url" Target="_blank">
                    <img src="@item.Image" alt="@item.Name" loading="lazy" />
                    <div class="content">
                        <div class="name title-medium">@item.Name</div>
                    </div>

                </MDCard>
            }
        </div>
    </section>
</CnGalWebSite.Components.Containers.MiniModeContainer>
@code {

    List<FriendLinkItemModel> _items { get; set; } = new List<FriendLinkItemModel>();

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }


    protected override async Task OnInitializedAsync()
    {
        try
        {
            //获取主页信息
            _items = await _pageModelCatche.GetCache("api/home/ListFriendLinks");
            StateHasChanged();
        }
        catch (Exception ex)
        {
            await ErrorHandler.ProcessError(ex, "获取主页友情链接列表失败");
        }
    }
}
